<template>
  <view>
    <view class="search-box">
      <my-search @click="mySearchClickHandel"></my-search>
    </view>
      <!-- 轮播图区域 -->
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
      <swiper-item v-for="(item,index) in swiperList" :key="item.goods_id">
        <navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id='+ item.goods_id">
          <image :src="item.image_src" ></image>
        </navigator>
      </swiper-item>
    </swiper>
    
    <!-- 分类导航区域 -->
    <view class="nav_list">
      <view class="nav_item" v-for="(item,index) in navList" :key="index" @click="navClickHandel(item)">
        <image :src="item.image_src" class="nav_img"></image>
      </view>
    </view>
    
    <!-- 楼层区域 -->
    <view class="floor_list">
      <!-- 每个楼层 -->
      <view class="floor_item" v-for="(item,index) in floorList" :key="index">
        <!-- 楼层标题 -->
        <image :src="item.floor_title.image_src" class="floor_title"></image>
        <!-- 楼层图片 -->
        <view class="floor_img_box">
          <!-- 左侧图片 -->
          <navigator class="right_img_box" :url="item.product_list[0].url">
            <image :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width +'rpx'}" mode="widthFix"></image>
          </navigator>
          <!-- 右侧图片 -->
          <view class="right_img_box">
            <navigator class="right_img_item" v-for="(item2,index2) in item.product_list" :key="index2" :url="item2.url">
              <image :src="item2.image_src" mode="widthFix" :style="{width:item2.image_width +'rpx'}" v-if="index2!==0"></image>
            </navigator>
          </view>
        </view>
      </view>
      
    </view>
    
  </view>
</template>

<script>
    import tabbarBadge from '../../mixins/tabbar-badge';
  export default {
        mixins:[tabbarBadge],
    data() {
      return {
        //轮播图数据
        swiperList:[],
        //分类导航数据
        navList:[],
        //楼层数据
        floorList:[]
      }
    },
    onLoad() {
      this.getSwiperList()
      this.getNavList()
      this.getFloorList()
    },
    methods:{
    async getSwiperList(){
    const res =  await uni.$http.get('/api/public/v1/home/swiperdata')
        if(res.data.meta.status!==200)return uni.$showMsg
        uni.$showMsg('请求成功')
       this.swiperList =  res.data.message
      },
     async getNavList(){
        const res = await uni.$http.get('/api/public/v1/home/catitems')
        if(res.data.meta.status!==200)return uni.$showMsg
         uni.$showMsg('请求成功')
        this.navList =  res.data.message
      },
      navClickHandel(item){
        if(item.name === '分类'){
          uni.switchTab({
            url:'/pages/cate/cate'
          })
        }
      },
     async getFloorList(){
       const res = await uni.$http.get('/api/public/v1/home/floordata') 
       if(res.data.meta.status!==200)return uni.$showMsg
       res.data.message.forEach(item=>{
         item.product_list.forEach(floor=>{
           floor.url = '/subpkg/goods_list/goods_list?' + floor.navigator_url.split('?')[1]
         })
       })
       this.floorList =  res.data.message
      },
      mySearchClickHandel(){
        uni.navigateTo({
          url:'/subpkg/search/search'
        })
      }
    }
  }
</script>

<style lang="scss">
swiper {
  height: 330rpx;
  .swiper-item,
  image {
    width: 100%;
    height: 100%;
  }
}
.nav_list {
  display: flex;
  justify-content: space-around;
  margin: 15px 0;
  .nav_img{
    width: 128rpx;
    height: 140rpx;
  }
}

.floor_title{
  width: 100%;
  height: 60rpx;
}

.floor_img_box{
  display: flex;
  padding-left: 10rpx;
}
.right_img_box{
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
}
.search-box{
  position: sticky;
  top: 0;
  z-index: 999;
  }
</style>
